﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

/// <summary>
/// NewDao 的摘要说明
/// </summary>
public class NewDao
{
	public NewDao()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
    }
    //点击，增加点击量 
    public static void click(string id)
    {
        OleDbConnection conn = DB.conn();
        if (conn != null && id!=null && id.Trim().Length > 0)
        {
            conn.Open();
            OleDbCommand comm = new OleDbCommand();
            comm.Connection = conn;
            comm.CommandText = "update news set clickNum=clickNum+1 where newId=" + id;
            try { comm.ExecuteNonQuery(); }
            catch (Exception ex) { throw ex; }
            finally { comm.Dispose(); conn.Close(); }
        }
    }
    /// <summary>
    /// 获取指定栏目第一篇文章内容
    /// </summary>
    /// <param name="pl"></param>
    /// <returns></returns>
    public static DataTable topOne(String pl)
    {
        OleDbConnection conn = DB.conn();
        if (conn != null)
        {
            conn.Open();
            OleDbCommand comm = new OleDbCommand();
            comm.Connection = conn;
            comm.CommandText = "select top 1 * from news where channelid in (select channel_id from channel where pageLocation='" + pl + "')  order by adddate desc ,newid desc";
            try
            {
                OleDbDataAdapter da = new OleDbDataAdapter();
                da.SelectCommand = comm;
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
            catch (Exception ex) { throw ex; }
            finally { comm.Dispose(); conn.Close(); }
        }
        return null;
    }
    /// <summary>
    /// 根据id获取栏目
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    public static DataTable findChanelByNewId(String id)
    {
        OleDbConnection conn = DB.conn();
        if (conn != null)
        {
            conn.Open();
            OleDbCommand comm = new OleDbCommand();
            comm.Connection = conn;
            comm.CommandText = "select * from channel where channel_id in (select channelid from news where newId=" + id + ")";
            try
            {
                OleDbDataAdapter da = new OleDbDataAdapter();
                da.SelectCommand = comm;
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
            catch (Exception ex) { throw ex; }
            finally { comm.Dispose(); conn.Close(); }
        }
        return null;
    }
    /// <summary>
    /// 根据id获取信息
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    public static DataTable findById(String id)
    {
        OleDbConnection conn = DB.conn();
        if (conn != null)
        {
            conn.Open();
            OleDbCommand comm = new OleDbCommand();
            comm.Connection = conn;
            comm.CommandText = "select * from news where newId=" + id;
            try
            {
                OleDbDataAdapter da = new OleDbDataAdapter();
                da.SelectCommand = comm;
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
            catch (Exception ex) { throw ex; }
            finally { comm.Dispose(); conn.Close(); }
        }
        return null;
    }
}
